<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>欢迎页面-X-admin2.0</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="../static/css/back/font.css">
<link rel="stylesheet" href="../static/css/back/xadmin.css">

<style type="text/css">
.s-logo {
	width: 100px;
	height: 100px;
}

.s-logo>img {
	width: 100%;
	height: 100%;
}

.s-info {
	float: left;
	margin-left: 20px;
}

.ss-info {
	margin-top: 20px;
}

.s-info2 {
	line-height: 52px;
}

.s-info3 {
	float: right;
}

.layui-nav-child {
	position: absolute !important;
	margin-top: 45px;
	width: 400px;
	left: -201px;
	border: 1px #101010 solid !important;
	z-index: 2 !important;
	 white-space: normal !important;
	 
}
.layui-nav-child dd {
	 margin: 10px 0;
}
.btn-clo{
	border: 1px red solid;
    border-radius: 3px;
    width: 60px;
    text-align: center;
    margin: 5px;
    height: 25px !important;
    line-height: 26px !important;
    color: red !important;
    float: left;
    margin-right: 10px;
}

.btn-clo+span{
	line-height: 20px !important;
    display: block;
    color: #999;
}
.layui-bg-cyan:hover {
	color: red;
}

.layui-col-xs4,.layui-col-xs3{
	text-align: center;
}
.yy-stat{
	border: 0px red solid;
    width: 250px;
    margin: 0 auto;
    line-height: 45px;
    border-radius: 15px;
    padding: 20px 10px;
    color: #fff;
    background-color: #70B2FC;
}
.yy-stat p:nth-child(1){
	font-size: 17px;
}
.yy-stat p:nth-child(2){
	font-size: 25px;
	font-weight: bold;
}
.yy-stat{
	font-size: 12px;
}

.layui-col-xs4:nth-of-type(2) .yy-stat{
	background-color: #6DDDB5 !important;
}
.layui-col-xs4:nth-of-type(3) .yy-stat{
	background-color: #F7C069 !important;
	width: 350px;
}

.wm-stat,.ts-stat{
	    border: 1px #f8f8f8 solid;
    width: 200px;
    margin: 0 auto;
    height: 200px;
    overflow: hidden;
}
.wm-stat p:nth-child(1),.ts-stat p:nth-child(1){
    background-color: #70b2fc;
    height: 50px;
    line-height: 50px;
    color: #fff;
    font-size: 15px;
    
    
}
.wm-stat p:nth-child(2),.ts-stat p:nth-child(2){
    background-color: #f8f8f8;
    height: 100%;
    line-height: 130px;
    font-size: 30px;
}
.openHours{
	color: black;
	margin-left: 10px;
}
</style>

</head>
<body>

	<div class="x-body">
		<div class="ss-info layui-form-item">
			<div class="s-logo s-info">
				<img alt="" src="">
			</div>
			<div class="s-info  s-info2 layui-input-inline">
				<h2></h2>
				<p></p>
			</div>
			<div class="s-info3">
				<ul class="layui-nav layui-nav-tree layui-bg-cyan layui-inline" lay-filter="demo">
					  <li class="layui-nav-item" >
					    <a href="javascript:;" class="show-sta-info"><span>关店中</span></a>
					    <dl class="layui-nav-child" style="background-color:#fff !important;">
					      <dd><a class="btn-clo" data-status="1" href="javascript:;">关店</a><span>当您希望长时间不再接受新订单时，可点击“关店”按钮来停止营业，启动后需手动恢复</span></dd>
					      <dd class=""><a class="btn-clo" data-status="2" href="javascript:;">开张</a><span>当您希望接受新订单时，可点击“开张”按钮来停止营业，启动后需手动恢复</span></dd>
					      <dd><hr></dd>
					      <dd><a class="btn-clo" data-status="3" href="javascript:;">营业调整</a><span>如您期望调整当前营业状态，可更改营业时间、预订设置</span></dd>
					      <dd class="hide"><span class="openHours">营业时间:</span></dd>
					    </dl>
					  </li>
					</ul>
			</div>
		</div>
		
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		  <legend>营业状态</legend>
		</fieldset>
		
		  <div class="layui-row">
		    <div class="layui-col-xs4">
		       <div class="yy-stat">
		       		<p>今日营业额</p>
		       		<p>¥0.00</p>
		       		<p>微信支付: ¥0.00</p>
		       		<p>现金结算: ¥0.00</p>
		       </div>
		    </div>
		    <div class="layui-col-xs4">
		      <div class="yy-stat">
		       		<p>今日订单</p>
		       		<p>0</p>
		       		<p>外卖订单：0</p>
		       		<p>堂食订单：0</p>
		       </div>
		    </div>
		    <div class="layui-col-xs4">
		      <div class="yy-stat">
		       		<p>总营业额</p>
		       		<p>¥0.00</p>
		       		<p>微信支付: ¥0.00</p>
		       		<p>现金结算: ¥0.00</p>
		       </div>
		    </div>
		  </div>
		  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		  <legend>外卖订单概况</legend>
		</fieldset>
		<div class="layui-row">
		    <div class="layui-col-xs3">
		       <div class="wm-stat">
		       		<p>今日有效订单</p>
		       		<p></p>
		       </div>
		    </div>
		    <div class="layui-col-xs3">
		       <div class="wm-stat">
		       		<p>今日微信支付订单</p>
		       		<p></p>
		       </div>
		    </div>
		    <div class="layui-col-xs3">
		       <div class="wm-stat">
		       		<p>今日现金结算订单</p>
		       		<p></p>
		       </div>
		    </div>
		    <div class="layui-col-xs3">
		       <div class="wm-stat">
		       		<p>今日关闭订单</p>
		       		<p></p>
		       </div>
		    </div>
		</div>
		  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		  <legend>堂食订单概况</legend>
		</fieldset>
		<div class="layui-row">
		    <div class="layui-col-xs3">
		       <div class="ts-stat">
		       		<p>今日有效订单</p>
		       		<p></p>
		       </div>
		    </div>
		    <div class="layui-col-xs3">
		       <div class="ts-stat">
		       		<p>今日微信支付订单</p>
		       		<p></p>
		       </div>
		    </div>
		    <div class="layui-col-xs3">
		       <div class="ts-stat">
		       		<p>今日现金结算订单</p>
		       		<p></p>
		       </div>
		    </div>
		    <div class="layui-col-xs3">
		       <div class="ts-stat">
		       		<p>今日关闭订单</p>
		       		<p></p>
		       </div>
		    </div>
		</div>
		    
		  <!--  -->
	</div>
</body>

<script type="text/javascript" src="../static/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../static/js/layui/layui.js"></script>
<script type="text/javascript" src="../static/js/back/ajax.js"></script>
<script type="text/javascript" src="../static/js/back/utils.js"></script>
<script type="text/javascript">
var spid ;
layui.use(['element'], function(){
		var $=layui.jquery;
			//监听导航点击
		spid = getCookie('shop_id');
	 	$(".btn-clo").click(function(){
	 		console.log($(this).text());
	 		$(this).parent().removeClass("layui-this");
	 		var ddt = $(this).attr("data-status");
	 		var ty = 0;
	 		if(ddt == 2){
	 			ty=1;
		 		$(".show-sta-info span").text('营业中');
	 			$(this).parent().addClass('hide').siblings().removeClass('hide');
	 		}else if(ddt == 1){
	 			ty=3;
		 		$(".show-sta-info span").text('关店中');
 				$(this).parent().addClass('hide').siblings().removeClass('hide');
	 		}else if(ddt == 3){
	 			if($(".show-sta-info").attr('data-status') == 3){
	 				parent.clickMenuOnChild('shops~shop-info-time.html');
	 				return;
	 			}
	 			ty=2;
		 		$(".show-sta-info span").text('待开始营业');
	 		}
	 		$(".show-sta-info").click();
	 		$(".show-sta-info").attr('data-status',ddt);
	 		//修改店铺运营状态
	 		console.log(ty);
	 		if(ty && ty!=0){
		 		updateShopInfo(ty);
	 		}
	 	})
	 	//查询店铺信息
	 	 getShopInfo();
		//查询订单概况
		getTodayOrderInfo();
	});
	
	function getTodayOrderInfo(){
		_ajax_post_token('../order/getShopTodayFirgit',{shopId:spid},function(res){
			console.log(res);
			var dd = res.returnObject;
			if(dd){
				$(".yy-stat").eq(0).find("p").eq(1).text('¥'+(dd.todayyyeCount / 100 ).toFixed(2));
				$(".yy-stat").eq(0).find("p").eq(2).text('微信支付: ¥'+(dd.wxTodayyyeCount / 100 ).toFixed(2));
				$(".yy-stat").eq(0).find("p").eq(3).text('现金结算: ¥'+(dd.xxTodayyyeCount / 100 ).toFixed(2));
				$(".yy-stat").eq(1).find("p").eq(1).text(dd.orderCount);
				$(".yy-stat").eq(1).find("p").eq(2).text("外卖订单: "+dd.outOrderCount);
				$(".yy-stat").eq(1).find("p").eq(3).text("堂食订单: "+dd.roomOrderCount);
				$(".yy-stat").eq(2).find("p").eq(1).text('¥'+(Number(dd.yyeCount) / 100 ).toFixed(2));
				$(".yy-stat").eq(2).find("p").eq(2).text('微信支付: ¥'+(dd.wxyyeCount / 100 ).toFixed(2));
				$(".yy-stat").eq(2).find("p").eq(3).text('现金结算: ¥'+(dd.xxyyeCount / 100 ).toFixed(2));
				
// 				$(".wm-stat").eq(0).find("p").eq(1).text(dd.outOrderCountYes);
				$(".wm-stat").eq(0).find("p").eq(1).text(dd.wxOutOrderCountYes+dd.xxOutOrderCountYes);
				$(".wm-stat").eq(1).find("p").eq(1).text(dd.wxOutOrderCountYes);
				$(".wm-stat").eq(2).find("p").eq(1).text(dd.xxOutOrderCountYes);
				$(".wm-stat").eq(3).find("p").eq(1).text(dd.outOrderCountClose);
				
// 				$(".ts-stat").eq(0).find("p").eq(1).text(dd.roomOrderCountYes) ;
				$(".ts-stat").eq(0).find("p").eq(1).text(dd.wxRoomOrderCountYes+ dd.xxRoomOrderCountYes) ;
				$(".ts-stat").eq(1).find("p").eq(1).text(dd.wxRoomOrderCountYes);
				$(".ts-stat").eq(2).find("p").eq(1).text(dd.xxRoomOrderCountYes);
				$(".ts-stat").eq(3).find("p").eq(1).text(dd.roomOrderCountClose);
			}
		});
	}
	
	function updateShopInfo(ty){
		console.log(ty);
		_ajax_post_token('../shop/updateShopInfoOnly.do',{id:spid,shopStatus:ty},function(res){
			console.log(res);
		})
	}
	function getShopInfo(){
		var spid = getCookie('shop_id');
		_ajax_post_token('../shop/getShopById',{id:spid},function(res){
			console.log(res);
			var dd = res.returnObject;
			if(dd){
				$(".s-logo img").attr("src",dd.shopLogo);
				$(".s-info2 h2").text(dd.shopTitle);
				$(".s-info2 p").text(formatDate(dd.serverEndTime,'YY-MM-DD')+" 到期" +(dd.serverEndTime<new Date()?'<span color="x-red">(已过期)</span>':''));
				if(dd.shopStatus == 1 ){
					var tiflag = false;
					if(dd.openHours){
						var tims = dd.openHours.split(",");
						console.log(tims);
						for (var i = 0; i < tims.length; i++) {
							tiflag = timeRange(tims[i].split("-")[0],tims[i].split("-")[1]);
							if(tiflag){
								break;								
							}
						}
					}
						console.log(tiflag);
						//不在营业时间内
						if(!tiflag){
							console.log(tiflag);
							$('.show-sta-info span').text('待开始营业');
							$(".btn-clo[data-status=2]").parent().addClass('hide');
							$('.show-sta-info').attr('data-status',3);								
						}else{
							$('.show-sta-info span').text('营业中');
							$(".btn-clo[data-status=2]").parent().addClass('hide');
						}
					
					
					
				}else  if(dd.shopStatus == 3 ){
					$('.show-sta-info span').text('关店中');
					$(".btn-clo[data-status=1]").parent().addClass('hide');
				}else  if(dd.shopStatus == 2 ){
					$('.show-sta-info span').text('待开始营业');
					$(".btn-clo[data-status=2]").parent().addClass('hide');
					$('.show-sta-info').attr('data-status',3);
				}
				if(dd.openHours){
					var reg = new RegExp( ',' , "g" );
					$(".openHours").text("营业时间  "+dd.openHours.replace(reg," ")).parent().show();
				}
			}
		});
	}
</script>

</html>